﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToRTR.CApExportToRTRRobotCollisionSetsData
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.Generic;
using System.Linq;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ExportToRTR{

internal class CApExportToRTRRobotCollisionSetsData
{
  private List<(CApExportToRTRRobotCollisionSetsData.CollisionList, List<CApExportToRTRRobotCollisionSetsData.CollisionList>)> _robotListsToStaticList = new List<(CApExportToRTRRobotCollisionSetsData.CollisionList, List<CApExportToRTRRobotCollisionSetsData.CollisionList>)>();
  private List<(CApExportToRTRRobotCollisionSetsData.CollisionList, List<CApExportToRTRRobotCollisionSetsData.CollisionList>)> _robotListsToOwnList = new List<(CApExportToRTRRobotCollisionSetsData.CollisionList, List<CApExportToRTRRobotCollisionSetsData.CollisionList>)>();

  public List<(List<ITxLocatableObject>, List<List<ITxLocatableObject>>)> RobotListsToStaticLists()
  {
    return this.RobotListsToLCollidingWithLists(this._robotListsToStaticList);
  }

  public List<(List<ITxLocatableObject>, List<List<ITxLocatableObject>>)> RobotListsToOwnLists()
  {
    return this.RobotListsToLCollidingWithLists(this._robotListsToOwnList);
  }

  private List<(List<ITxLocatableObject>, List<List<ITxLocatableObject>>)> RobotListsToLCollidingWithLists(
    List<(CApExportToRTRRobotCollisionSetsData.CollisionList, List<CApExportToRTRRobotCollisionSetsData.CollisionList>)> listToExtract)
  {
    List<(List<ITxLocatableObject>, List<List<ITxLocatableObject>>)> lcollidingWithLists = new List<(List<ITxLocatableObject>, List<List<ITxLocatableObject>>)>();
    foreach ((CApExportToRTRRobotCollisionSetsData.CollisionList, List<CApExportToRTRRobotCollisionSetsData.CollisionList>) tuple in listToExtract)
    {
      List<List<ITxLocatableObject>> itxLocatableObjectListList = new List<List<ITxLocatableObject>>();
      foreach (CApExportToRTRRobotCollisionSetsData.CollisionList collisionList in tuple.Item2)
        itxLocatableObjectListList.Add(collisionList.Objects.ToList<ITxLocatableObject>());
      lcollidingWithLists.Add((tuple.Item1.Objects.ToList<ITxLocatableObject>(), itxLocatableObjectListList));
    }
    return lcollidingWithLists;
  }

  public void AddStaticCollisionSets(
    List<ITxLocatableObject> robotSet,
    List<ITxLocatableObject> staticSet)
  {
    this.AddRobotCollisionSets(robotSet, staticSet, this._robotListsToStaticList);
  }

  public void AddRobotOwnCollisionSets(
    List<ITxLocatableObject> robotSet,
    List<ITxLocatableObject> ownSet)
  {
    this.AddRobotCollisionSets(robotSet, ownSet, this._robotListsToOwnList);
  }

  private void AddRobotCollisionSets(
    List<ITxLocatableObject> robotSet,
    List<ITxLocatableObject> collidingSet,
    List<(CApExportToRTRRobotCollisionSetsData.CollisionList, List<CApExportToRTRRobotCollisionSetsData.CollisionList>)> robotListsToCollidingList)
  {
    CApExportToRTRRobotCollisionSetsData.CollisionList other1 = new CApExportToRTRRobotCollisionSetsData.CollisionList(robotSet);
    CApExportToRTRRobotCollisionSetsData.CollisionList other2 = new CApExportToRTRRobotCollisionSetsData.CollisionList(collidingSet);
    bool flag1 = true;
    foreach ((CApExportToRTRRobotCollisionSetsData.CollisionList, List<CApExportToRTRRobotCollisionSetsData.CollisionList>) listsToColliding in robotListsToCollidingList)
    {
      if (listsToColliding.Item1.ListEqauls(other1))
      {
        flag1 = false;
        bool flag2 = true;
        foreach (CApExportToRTRRobotCollisionSetsData.CollisionList collisionList in listsToColliding.Item2)
        {
          if (collisionList.ListEqauls(other2))
          {
            flag2 = false;
            break;
          }
        }
        if (flag2)
        {
          listsToColliding.Item2.Add(other2);
          break;
        }
      }
    }
    if (!flag1)
      return;
    robotListsToCollidingList.Add((other1, new List<CApExportToRTRRobotCollisionSetsData.CollisionList>()
    {
      other2
    }));
  }

  private class CollisionList
  {
    internal HashSet<ITxLocatableObject> Objects { get; }

    internal CollisionList(List<ITxLocatableObject> staticSet)
    {
      this.Objects = new HashSet<ITxLocatableObject>((IEnumerable<ITxLocatableObject>) staticSet);
    }

    internal bool ListEqauls(
      CApExportToRTRRobotCollisionSetsData.CollisionList other)
    {
      return this.Objects.SetEquals((IEnumerable<ITxLocatableObject>) other.Objects);
    }
  }
}
